<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<title>Lifetime - cppreference.com</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../common/favicon.ico">
<link rel="stylesheet" href="../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-css:7:472787eddcf4605d11de8c7ef047234f */</style>

<script src="../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"cpp/language/lifetime","wgTitle":"cpp/language/lifetime","wgCurRevisionId":141373,"wgArticleId":13096,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Pages with unreviewed CWG DR marker","Todo with reason"],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"cpp/language/lifetime","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"en","language":"en","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-ColiruCompiler":1,"gadget-MathJax":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-js:7:9f05c6caceb9bb1a482b6cebd4c5a330 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_language_lifetime skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading">Lifetime</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">From cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../cpp.html" title="cpp">cpp</a>‎ | <a href="../language.html" title="cpp/language">language</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../compiler_support.html" title="cpp/compiler support"> Compiler support</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../freestanding.html" title="cpp/freestanding"> Freestanding and hosted</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../language.html" title="cpp/language"> Language</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../header.html" title="cpp/header"> Standard library headers</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../named_req.html" title="cpp/named req"> Named requirements </a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../feature_test.html" title="cpp/feature test"> Feature test macros </a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html#Language_support" title="cpp/utility"> Language support library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../concepts.html" title="cpp/concepts"> Concepts library</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../meta.html" title="cpp/meta"> Metaprogramming library</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../error.html" title="cpp/error"> Diagnostics library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html" title="cpp/utility"> General utilities library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../string.html" title="cpp/string"> Strings library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../container.html" title="cpp/container"> Containers library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../iterator.html" title="cpp/iterator"> Iterators library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../ranges.html" title="cpp/ranges"> Ranges library</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../algorithm.html" title="cpp/algorithm"> Algorithms library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../numeric.html" title="cpp/numeric"> Numerics library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../locale.html" title="cpp/locale"> Localizations library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../io.html" title="cpp/io"> Input/output library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../filesystem.html" title="cpp/filesystem"> Filesystem library</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../regex.html" title="cpp/regex"> Regular expressions library</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../thread.html" title="cpp/thread"> Concurrency support library</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../experimental.html" title="cpp/experimental"> Technical specifications</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../symbol_index.html" title="cpp/symbol index"> Symbols index</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../links/libs.html" title="cpp/links/libs"> External libraries</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../language.html" title="cpp/language"> C++ language</a><div class="t-navbar-menu"><div><div style="display:inline-block">
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> General topics</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../preprocessor.html" title="cpp/preprocessor"> Preprocessor</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../comments.html" title="cpp/comment"> Comments</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../keywords.html" title="cpp/keyword"> Keywords</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="escape.html" title="cpp/language/escape"> Escape sequences</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> <a href="statements.html" title="cpp/language/statements"> Flow control</a></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Conditional execution statements</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="if.html" title="cpp/language/if"><tt>if</tt></a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="switch.html" title="cpp/language/switch"><tt>switch</tt></a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Iteration statements (loops)</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="for.html" title="cpp/language/for"><tt>for</tt></a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="range-for.html" title="cpp/language/range-for"> range-<code>for</code></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="while.html" title="cpp/language/while"><tt>while</tt></a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="do.html" title="cpp/language/do"> <code>do-while</code></a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Jump statements </td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="continue.html" title="cpp/language/continue"><tt>continue</tt></a> - <a href="break.html" title="cpp/language/break"><tt>break</tt></a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="goto.html" title="cpp/language/goto"><tt>goto</tt></a> - <a href="return.html" title="cpp/language/return"><tt>return</tt></a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> <a href="functions.html" title="cpp/language/functions"> Functions</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="function.html" title="cpp/language/function"> Function declaration</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="lambda.html" title="cpp/language/lambda"> Lambda function expression</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="inline.html" title="cpp/language/inline"> <code>inline</code> specifier</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="except_spec.html" title="cpp/language/except spec"> Dynamic exception specifications</a> <span class="t-mark-rev t-until-cxx20">(until C++20)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="noexcept_spec.html" title="cpp/language/noexcept spec"> <code>noexcept</code> specifier</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Exceptions</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="throw.html" title="cpp/language/throw"> <code>throw</code>-expression</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="try_catch.html" title="cpp/language/try catch"> <code>try</code>-<code>catch</code> block</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Namespaces</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="namespace.html" title="cpp/language/namespace"> Namespace declaration</a>  </td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="namespace_alias.html" title="cpp/language/namespace alias"> Namespace aliases</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Types</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="types.html" title="cpp/language/types"> Fundamental types</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="enum_class.html" title="cpp/language/enum"> Enumeration types</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="function.html" title="cpp/language/function"> Function types</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="class.html" title="cpp/language/class"> Class/struct types</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="union.html" title="cpp/language/union"> Union types</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Specifiers</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="decltype.html" title="cpp/language/decltype"><tt>decltype</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="auto.html" title="cpp/language/auto"><tt>auto</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="alignas.html" title="cpp/language/alignas"><tt>alignas</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="cv.html" title="cpp/language/cv"> <code>const</code>/<code>volatile</code></a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="constexpr.html" title="cpp/language/constexpr"><tt>constexpr</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="storage_duration.html" title="cpp/language/storage duration"> Storage duration specifiers</a></td></tr>
<tr class="t-nv-h2"><td colspan="5"> <a href="initialization.html" title="cpp/language/initialization"> Initialization</a></td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="default_initialization.html" title="cpp/language/default initialization"> Default initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="value_initialization.html" title="cpp/language/value initialization"> Value initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="zero_initialization.html" title="cpp/language/zero initialization"> Zero initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="copy_initialization.html" title="cpp/language/copy initialization"> Copy initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="direct_initialization.html" title="cpp/language/direct initialization"> Direct initialization</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="aggregate_initialization.html" title="cpp/language/aggregate initialization"> Aggregate initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="list_initialization.html" title="cpp/language/list initialization"> List initialization</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="constant_initialization.html" title="cpp/language/constant initialization"> Constant initialization</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="reference_initialization.html" title="cpp/language/reference initialization"> Reference initialization</a></td></tr>
</table></div></td></tr>
</table></div>
</div>
<div style="display:inline-block">
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> <a href="expressions.html" title="cpp/language/expressions"> Expressions</a></td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="value_category.html" title="cpp/language/value category"> Value categories</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="eval_order.html" title="cpp/language/eval order"> Order of evaluation</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="operators.html" title="cpp/language/operators"> Operators</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="operator_precedence.html" title="cpp/language/operator precedence"> Operator precedence</a></td></tr>
</table></div></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="operator_alternative.html" title="cpp/language/operator alternative"> Alternative representations</a></td></tr>
<tr class="t-nv-h2"><td colspan="5"> <a href="expressions.html#Literals" title="cpp/language/expressions"> Literals</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="bool_literal.html" title="cpp/language/bool literal"> Boolean</a> - <a href="integer_literal.html" title="cpp/language/integer literal"> Integer</a> - <a href="floating_literal.html" title="cpp/language/floating literal"> Floating-point</a></td></tr>   
<tr class="t-nv"><td colspan="5"> <a href="character_literal.html" title="cpp/language/character literal"> Character</a> - <a href="string_literal.html" title="cpp/language/string literal"> String</a> - <a href="nullptr.html" title="cpp/language/nullptr"><tt>nullptr</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr> 
<tr class="t-nv"><td colspan="5"> <a href="user_literal.html" title="cpp/language/user literal"> User-defined</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Utilities</td></tr>
<tr class="t-nv"><td colspan="5"> <a href="attributes.html" title="cpp/language/attributes"> Attributes</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Types</td></tr>
<tr class="t-nv"><td colspan="5"> <a href="typedef.html" title="cpp/language/typedef"> <code>typedef</code> declaration</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="type_alias.html" title="cpp/language/type alias"> Type alias declaration</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Casts</td></tr>
<tr class="t-nv"><td colspan="5"> <a href="implicit_cast.html" title="cpp/language/implicit conversion"> Implicit conversions</a> - <a href="explicit_cast.html" title="cpp/language/explicit cast"> Explicit conversions</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="static_cast.html" title="cpp/language/static cast"><tt>static_cast</tt></a> - <a href="dynamic_cast.html" title="cpp/language/dynamic cast"><tt>dynamic_cast</tt></a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="const_cast.html" title="cpp/language/const cast"><tt>const_cast</tt></a> - <a href="reinterpret_cast.html" title="cpp/language/reinterpret cast"><tt>reinterpret_cast</tt></a></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Memory allocation</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="new.html" title="cpp/language/new"> <code>new</code> expression</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="delete.html" title="cpp/language/delete"> <code>delete</code> expression</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> <a href="classes.html" title="cpp/language/classes"> Classes</a></td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="class.html" title="cpp/language/class"> Class declaration</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="initializer_list.html" title="cpp/language/constructor"> Constructors</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="this.html" title="cpp/language/this"> <code>this</code> pointer</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="access.html" title="cpp/language/access"> Access specifiers</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="friend.html" title="cpp/language/friend"> <code>friend</code> specifier</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Class-specific function properties</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="virtual.html" title="cpp/language/virtual"> Virtual function</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="override.html" title="cpp/language/override"> <code>override</code> specifier</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="final.html" title="cpp/language/final"> <code>final</code> specifier</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="explicit.html" title="cpp/language/explicit"><tt>explicit</tt></a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="static.html" title="cpp/language/static"><tt>static</tt></a> </td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Special member functions</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="default_constructor.html" title="cpp/language/default constructor"> Default constructor</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="copy_constructor.html" title="cpp/language/copy constructor"> Copy constructor</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="move_constructor.html" title="cpp/language/move constructor"> Move constructor</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="as_operator.html" title="cpp/language/as operator" class="mw-redirect"> Copy assignment</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="move_operator.html" title="cpp/language/move operator" class="mw-redirect"> Move assignment</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="destructor.html" title="cpp/language/destructor"> Destructor</a></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"><a href="templates.html" title="cpp/language/templates"> Templates</a> </td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="class_template.html" title="cpp/language/class template"> Class template </a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="function_template.html" title="cpp/language/function template"> Function template </a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="template_specialization.html" title="cpp/language/template specialization"> Template specialization</a></td></tr>   
<tr class="t-nv"><td colspan="5"> <a href="parameter_pack.html" title="cpp/language/parameter pack"> Parameter packs</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span></td></tr>
</table></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Miscellaneous </td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="asm.html" title="cpp/language/asm"> Inline assembly</a></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="history.html" title="cpp/language/history"> History of C++</a></td></tr>
</table></div></td></tr>
</table></div>
</div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="basic_concepts.html" title="cpp/language/basic concepts"> Basic Concepts</a><div class="t-navbar-menu"><div><div style="display:inline-block">
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../keywords.html" title="cpp/keyword"> Language keywords</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="charset.html" title="cpp/language/charset"> Character sets and encodings</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="translation_phases.html" title="cpp/language/translation phases"> Phases of translation</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../comments.html" title="cpp/comment"> Comments</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="main_function.html" title="cpp/language/main function"> The main() function</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="punctuators.html" title="cpp/language/punctuators"> Punctuation</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="name.html" title="cpp/language/identifiers"> Names and identifiers</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="type-id.html" title="cpp/language/type"> Types</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="types.html" title="cpp/language/types"> Fundamental types</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="objects.html" title="cpp/language/object"> Objects</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="scope.html" title="cpp/language/scope"> Scope</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <strong class="selflink"> Object lifetime</strong> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="storage_duration.html" title="cpp/language/storage duration"> Storage duration and linkage</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="definition.html" title="cpp/language/definition"> Definitions and ODR</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="lookup.html" title="cpp/language/lookup"> Name lookup</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="qualified_lookup.html" title="cpp/language/qualified lookup"> Qualified name lookup</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="unqualified_lookup.html" title="cpp/language/unqualified lookup"> Unqualified name lookup</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="as_if.html" title="cpp/language/as if"> The as-if rule</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="ub.html" title="cpp/language/ub"> Undefined behavior</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="memory_model.html" title="cpp/language/memory model"> Memory model</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="modules.html" title="cpp/language/modules"> Modules</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
</table></div>
</div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<p>Every <a href="objects.html" title="cpp/language/object">object</a> and <a href="reference.html" title="cpp/language/reference">reference</a> has a <i>lifetime</i>, which is a runtime property: for any object or reference, there is a point of execution of a program when its lifetime begins, and there is a moment when it ends.
</p><p>The lifetime of an object begins when: 
</p>
<ul><li> storage with the proper alignment and size for its type is obtained, and
</li><li> its initialization (if any) is complete (including <a href="default_initialization.html" title="cpp/language/default initialization">default initialization</a> via no constructor or <a href="default_constructor.html#Trivial_default_constructor" title="cpp/language/default constructor">trivial default constructor</a>), except that
</li></ul>
<dl><dd><ul><li> if the object is a <a href="union.html#Member_lifetime" title="cpp/language/union">union member</a> or subobject thereof, its lifetime only begins if that union member is the initialized member in the union, or it is made active,
</li><li> if the object is nested in a union object, its lifetime may begin if the containing union object is assigned or constructed by a trivial special member function,
</li><li> an array object's lifetime may also begin if it is allocated by <span class="t-lc"><a href="../memory/allocator/allocate.html" title="cpp/memory/allocator/allocate">std::allocator::allocate</a></span>.
</li></ul>
</dd></dl>
<p>Some operations <a href="objects.html#Object_creation" title="cpp/language/object">implicitly create objects</a> of <a href="../named_req/ImplicitLifetimeType.html" title="cpp/named req/ImplicitLifetimeType">implicit-lifetime types</a> in given region of storage and start their lifetime. If a subobject of an implicitly created object is not of an implicit-lifetime type, its lifetime does not begin implicitly.
</p><p>The lifetime of an object ends when: 
</p>
<ul><li> if it is of a non-class type, the object is destroyed (maybe via a pseudo-destructor call), or
</li><li> if it is of a class type, the <a href="destructor.html" title="cpp/language/destructor">destructor</a> call starts, or
</li><li> the storage which the object occupies is released, or is reused by an object that is not nested within it.
</li></ul>
<p>Lifetime of an object is equal to or is nested within the lifetime of its storage, see <a href="storage_duration.html" title="cpp/language/storage duration">storage duration</a>.
</p><p>The lifetime of a <a href="reference.html" title="cpp/language/reference">reference</a> begins when its initialization is complete and ends as if it were a scalar object. 
</p><p>Note: the lifetime of the referred object may end before the end of the lifetime of the reference, which makes <a href="reference.html#Dangling_references" title="cpp/language/reference">dangling references</a> possible.
</p><p>Lifetimes of non-static data members and base subobjects begin and end following <a href="initializer_list.html#Initialization_order" title="cpp/language/initializer list" class="mw-redirect">class initialization order</a>.
</p>
<h3><span class="mw-headline" id="Temporary_object_lifetime">Temporary object lifetime</span></h3>
<p>Temporary objects are created <span class="t-rev-inl t-since-cxx17"><span>when a prvalue is <a href="implicit_cast.html#Temporary_materialization" title="cpp/language/implicit conversion">materialized</a> so that it can be used as a glvalue, which occurs</span> <span><span class="t-mark-rev t-since-cxx17">(since C++17)</span></span></span> in the following situations:
</p>
<ul><li> <a href="reference_initialization.html" title="cpp/language/reference initialization">binding a reference to a prvalue</a>
</li></ul>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx11"><td>
<ul><li> <a href="list_initialization.html" title="cpp/language/list initialization">initializing</a> an object of type <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../utility/initializer_list.html"><span class="kw961">std::<span class="me2">initializer_list</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span></span></span> from a braced-init-list
</li></ul>
</td>
<td><span class="t-mark-rev t-since-cxx11">(since C++11)</span></td></tr>
</table>
 <table class="t-rev-begin">
<tr class="t-rev t-until-cxx17"><td>
<ul><li> returning a prvalue from a function
</li><li> <a href="expressions.html#Conversions" title="cpp/language/expressions">conversion</a> that creates a prvalue (<a href="explicit_cast.html" title="cpp/language/explicit cast">including</a> <span class="t-c"><span class="mw-geshi cpp source-cpp">T<span class="br0">(</span>a,b,c<span class="br0">)</span></span></span> and <span class="t-c"><span class="mw-geshi cpp source-cpp">T<span class="br0">{</span><span class="br0">}</span></span></span>)
</li></ul>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx11"><td>
<ul><li> <a href="lambda.html" title="cpp/language/lambda">lambda expression</a>
</li></ul>
</td>
<td><span class="t-mark-rev t-since-cxx11">(since C++11)</span></td></tr>
</table>
<ul><li> <a href="copy_initialization.html" title="cpp/language/copy initialization">copy-initialization</a> that requires conversion of the initializer,
</li><li> <a href="reference_initialization.html" title="cpp/language/reference initialization">reference-initialization</a> to a different but convertible type or to a bitfield.
</li></ul>
</td>
<td><span class="t-mark-rev t-until-cxx17">(until C++17)</span></td></tr>
<tr class="t-rev t-since-cxx17"><td>
<ul><li> when performing <a href="operator_member_access.html#Built-in_member_access_operators" title="cpp/language/operator member access">member access</a> on a class prvalue
</li><li> when performing an <a href="array.html#Array-to-pointer_decay" title="cpp/language/array">array-to-pointer</a> conversion or <a href="operator_member_access.html#Built-in_subscript_operator" title="cpp/language/operator member access">subscripting</a> on an array prvalue
</li><li> for unevaluated operands in <a href="sizeof.html" title="cpp/language/sizeof"><code>sizeof</code></a> and <a href="typeid.html" title="cpp/language/typeid"><code>typeid</code></a>
</li><li> when a prvalue appears as a <a href="expressions.html#Discarded-value_expressions" title="cpp/language/expressions">discarded-value expression</a>
</li><li> if supported by the implementation, when passing or returning an object of trivially-copyable type in a <a href="operator_other.html#Built-in_function_call_operator" title="cpp/language/operator other">function call expression</a> (this models passing structs in CPU registers)
</li></ul>
</td>
<td><span class="t-mark-rev t-since-cxx17">(since C++17)</span></td></tr>
</table>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx17"><td>
<p>The materialization of a temporary object is generally delayed as long as possible in order to avoid creating unnecessary temporary object: see <a href="copy_elision.html" title="cpp/language/copy elision">copy elision</a>.
</p>
</td>
<td><span class="t-mark-rev t-since-cxx17">(since C++17)</span></td></tr>
</table>
<p>All temporary objects are destroyed as the last step in evaluating the <a href="expressions.html#Full-expressions" title="cpp/language/expressions">full-expression</a> that (lexically) contains the point where they were created, and if multiple temporary objects were created, they are destroyed in the order opposite to the order of creation. This is true even if that evaluation ends in throwing an exception.
</p><p>There are two exceptions from that:
</p>
<ul><li> The lifetime of a temporary object may be extended by binding to a const lvalue reference <span class="t-rev-inl t-since-cxx11"><span>or to an rvalue reference</span> <span><span class="t-mark-rev t-since-cxx11">(since C++11)</span></span></span>, see <a href="reference_initialization.html#Lifetime_of_a_temporary" title="cpp/language/reference initialization">reference initialization</a> for details.
</li><li> The lifetime of a temporary object created when evaluating the default arguments of a default or copy constructor used to initialize or copy an element of an array ends before the next element of the array begins initialization.
</li></ul>
<h3><span class="mw-headline" id="Storage_reuse">Storage reuse</span></h3>
<p>A program is not required to call the destructor of an object to end its lifetime if the object is <a href="destructor.html#Trivial_destructor" title="cpp/language/destructor">trivially-destructible</a> or if the program does not rely on the side effects of the destructor. However, if a program ends the lifetime of an non-trivially destructible object that is a variable explicitly, it must ensure that a new object of the same type is constructed in-place (e.g. via placement new) before the destructor may be called implicitly, i.e. due to scope exit or exception for automatic objects, due to thread exit for thread-local objects, or due to program exit for static objects; otherwise the behavior is undefined.
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">class</span> T <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span> <span class="co1">// trivial</span>
 
<span class="kw1">struct</span> B
<span class="br0">{</span>
    ~B<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span><span class="br0">}</span> <span class="co1">// non-trivial</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">void</span> x<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">long</span> <span class="kw4">long</span> n<span class="sy4">;</span> <span class="co1">// automatic, trivial</span>
    new <span class="br0">(</span><span class="sy3">&amp;</span>n<span class="br0">)</span> <span class="kw4">double</span><span class="br0">(</span><span class="nu16">3.14</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// reuse with a different type okay</span>
<span class="br0">}</span> <span class="co1">// okay</span>
 
<span class="kw4">void</span> h<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    B b<span class="sy4">;</span> <span class="co1">// automatic non-trivially destructible</span>
    b.~B<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// end lifetime (not required, since no side-effects)</span>
    new <span class="br0">(</span><span class="sy3">&amp;</span>b<span class="br0">)</span> T<span class="sy4">;</span> <span class="co1">// wrong type: okay until the destructor is called</span>
<span class="br0">}</span> <span class="co1">// destructor is called: undefined behavior</span></pre></div></div>
<p>It is undefined behavior to reuse storage that is or was occupied by a const complete object of static, thread-local, or automatic storage duration because such objects may be stored in read-only memory.
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> B
<span class="br0">{</span>
    B<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// non-trivial</span>
    ~B<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// non-trivial</span>
<span class="br0">}</span><span class="sy4">;</span>
<span class="kw4">const</span> B b<span class="sy4">;</span> <span class="co1">// const static</span>
 
<span class="kw4">void</span> h<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    b.~B<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// end the lifetime of b</span>
    new <span class="br0">(</span><span class="kw1">const_cast</span><span class="sy1">&lt;</span>B<span class="sy2">*</span><span class="sy1">&gt;</span><span class="br0">(</span><span class="sy3">&amp;</span>b<span class="br0">)</span><span class="br0">)</span> <span class="kw4">const</span> B<span class="sy4">;</span> <span class="co1">// undefined behavior: attempted reuse of a const</span>
<span class="br0">}</span></pre></div></div>
<p>If a new object is created at the address that was occupied by another object, then all pointers, references, and the name of the original object will automatically refer to the new object and, once the lifetime of the new object begins, can be used to manipulate the new object, but only if the original object is transparently replaceable by the new object.
</p><p>Object <code>x</code> is <i>transparently replaceable</i> by object <code>y</code> if:
</p>
<ul><li> the storage for <code>y</code> exactly overlays the storage location which <code>x</code> occupied
</li><li> <code>y</code> is of the same type as <code>x</code> (ignoring the top-level cv-qualifiers)
</li><li> <code>x</code> is not a complete const object
</li><li> neither <code>x</code> nor <code>y</code> is a base class subobject<span class="t-rev-inl t-since-cxx20"><span>, or a member subobject declared with <code>[[<a href="attributes/no_unique_address.html" title="cpp/language/attributes/no unique address">no_unique_address</a>]]</code></span> <span><span class="t-mark-rev t-since-cxx20">(since C++20)</span></span></span>
</li><li> either
</li></ul>
<dl><dd><ul><li> <code>x</code> and <code>y</code> are both complete objects, or
</li><li> <code>x</code> and <code>y</code> are direct subobjects of objects <code>ox</code> and <code>oy</code> respectively, and <code>ox</code> is transparently replaceable by <code>oy</code>.
</li></ul>
</dd></dl>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> C
<span class="br0">{</span>
    <span class="kw4">int</span> i<span class="sy4">;</span>
    <span class="kw4">void</span> f<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="kw4">const</span> C<span class="sy3">&amp;</span> operator<span class="sy1">=</span><span class="br0">(</span><span class="kw4">const</span> C<span class="sy3">&amp;</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">const</span> C<span class="sy3">&amp;</span> C<span class="sy4">::</span><span class="me2">operator</span><span class="sy1">=</span><span class="br0">(</span><span class="kw4">const</span> C<span class="sy3">&amp;</span> other<span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw1">if</span> <span class="br0">(</span>this <span class="sy3">!</span><span class="sy1">=</span> <span class="sy3">&amp;</span>other<span class="br0">)</span>
    <span class="br0">{</span>
        this<span class="sy2">-</span><span class="sy1">&gt;</span>~C<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>          <span class="co1">// lifetime of *this ends</span>
        new <span class="br0">(</span>this<span class="br0">)</span> C<span class="br0">(</span>other<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// new object of type C created</span>
        f<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>                 <span class="co1">// well-defined</span>
    <span class="br0">}</span>
    <span class="kw1">return</span> <span class="sy2">*</span>this<span class="sy4">;</span>
<span class="br0">}</span>
 
C c1<span class="sy4">;</span>
C c2<span class="sy4">;</span>
c1 <span class="sy1">=</span> c2<span class="sy4">;</span> <span class="co1">// well-defined</span>
c1.<span class="me1">f</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>  <span class="co1">// well-defined; c1 refers to a new object of type C</span></pre></div></div>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx17"><td>
<p>If the conditions listed above are not met, a valid pointer to the new object may still be obtained by applying the pointer optimization barrier <span class="t-lc"><a href="../utility/launder.html" title="cpp/utility/launder">std::launder</a></span>:
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> A
<span class="br0">{</span> 
    <span class="kw1">virtual</span> <span class="kw4">int</span> transmogrify<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw1">struct</span> B <span class="sy4">:</span> A
<span class="br0">{</span>
    <span class="kw4">int</span> transmogrify<span class="br0">(</span><span class="br0">)</span> override <span class="br0">{</span> <span class="sy4">::</span><span class="me2">new</span><span class="br0">(</span>this<span class="br0">)</span> A<span class="sy4">;</span> <span class="kw1">return</span> <span class="nu0">2</span><span class="sy4">;</span> <span class="br0">}</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw1">inline</span> <span class="kw4">int</span> A<span class="sy4">::</span><span class="me2">transmogrify</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <span class="sy4">::</span><span class="me2">new</span><span class="br0">(</span>this<span class="br0">)</span> B<span class="sy4">;</span> <span class="kw1">return</span> <span class="nu0">1</span><span class="sy4">;</span> <span class="br0">}</span>
 
<span class="kw4">void</span> test<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    A i<span class="sy4">;</span>
    <span class="kw4">int</span> n <span class="sy1">=</span> i.<span class="me1">transmogrify</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="co1">// int m = i.transmogrify(); // undefined behavior:</span>
    <span class="co1">// the new A object is a base subobject, while the old one is a complete object</span>
    <span class="kw4">int</span> m <span class="sy1">=</span> <a href="../utility/launder.html"><span class="kw1125">std::<span class="me2">launder</span></span></a><span class="br0">(</span><span class="sy3">&amp;</span>i<span class="br0">)</span><span class="sy2">-</span><span class="sy1">&gt;</span>transmogrify<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// OK</span>
    <a href="../error/assert.html"><span class="kw775">assert</span></a><span class="br0">(</span>m <span class="sy2">+</span> n <span class="sy1">==</span> <span class="nu0">3</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
</td>
<td><span class="t-mark-rev t-since-cxx17">(since C++17)</span></td></tr>
</table>
<p>Similarly, if an object is created in the storage of a class member or array element, the created object is only a subobject (member or element) of the original object's containing object if:
</p>
<ul><li> the lifetime of the containing object has begun and not ended
</li><li> the storage for the new object exactly overlays the storage of the original object
</li><li> the new object is of the same type as the original object (ignoring cv-qualification).
</li></ul>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx17"><td>
<p>Otherwise, the name of the original subobject cannot be used to access the new object without <span class="t-lc"><a href="../utility/launder.html" title="cpp/utility/launder">std::launder</a></span>:
</p>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style=""><tr><td class="mbox-empty-cell"></td><td class="mbox-text" style="">This section is incomplete<br>Reason: an appropriate example </td></tr></table>
</td>
<td><span class="t-mark-rev t-since-cxx17">(since C++17)</span></td></tr>
</table>
<p>As a special case, objects can be created in arrays of <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> <span class="t-rev-inl t-since-cxx17"><span>or <a href="../types/byte.html" title="cpp/types/byte"><tt>std::byte</tt></a></span> <span><span class="t-mark-rev t-since-cxx17">(since C++17)</span></span></span> (in which case it is said that the array <i>provides storage</i> for the object) if
</p>
<ul><li> the lifetime of the array has begun and not ended
</li><li> the storage for the new object fits entirely within the array
</li><li> there is no array object that satisfies these constraints nested within the array.
</li></ul>
<p>If that portion of the array previously provided storage for another object, the lifetime of that object ends because its storage was reused, however the lifetime of the array itself does not end (its storage is not considered to have been reused)
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">typename</span>... <span class="me1">T</span><span class="sy1">&gt;</span>
<span class="kw1">struct</span> AlignedUnion
<span class="br0">{</span>
    alignas<span class="br0">(</span>T...<span class="br0">)</span> <span class="kw4">unsigned</span> <span class="kw4">char</span> data<span class="br0">[</span>max<span class="br0">(</span>sizeof<span class="br0">(</span>T<span class="br0">)</span>...<span class="br0">)</span><span class="br0">]</span><span class="sy4">;</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> f<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    AlignedUnion<span class="sy1">&lt;</span><span class="kw4">int</span>, <span class="kw4">char</span><span class="sy1">&gt;</span> au<span class="sy4">;</span>
    <span class="kw4">int</span> <span class="sy2">*</span>p <span class="sy1">=</span> new <span class="br0">(</span>au.<span class="me1">data</span><span class="br0">)</span> <span class="kw4">int</span><span class="sy4">;</span>     <span class="co1">// OK, au.data provides storage</span>
    <span class="kw4">char</span> <span class="sy2">*</span>c <span class="sy1">=</span> new <span class="br0">(</span>au.<span class="me1">data</span><span class="br0">)</span> <span class="kw4">char</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// OK, ends lifetime of *p</span>
    <span class="kw4">char</span> <span class="sy2">*</span>d <span class="sy1">=</span> new <span class="br0">(</span>au.<span class="me1">data</span> <span class="sy2">+</span> <span class="nu0">1</span><span class="br0">)</span> <span class="kw4">char</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
    <span class="kw1">return</span> <span class="sy2">*</span>c <span class="sy2">+</span> <span class="sy2">*</span>d<span class="sy4">;</span> <span class="co1">// OK</span>
<span class="br0">}</span></pre></div></div>
<h3><span class="mw-headline" id="Access_outside_of_lifetime">Access outside of lifetime</span></h3>
<p>Before the lifetime of an object has started but after the storage which the object will occupy has been allocated or, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, the behaviors of the following uses of the glvalue expression that identifies that object are undefined, unless the object is being constructed or destructed (separate set of rules applies):
</p>
<ol><li> Lvalue to rvalue conversion (e.g. function call to a function that takes a value).
</li><li> Access to a non-static data member or a call to a non-static member function.
</li><li> Binding a reference to a virtual base class subobject.
</li><li> <a href="dynamic_cast.html" title="cpp/language/dynamic cast"><code>dynamic_cast</code></a> or <a href="typeid.html" title="cpp/language/typeid"><code>typeid</code></a> expressions.
</li></ol>
<p>The above rules apply to pointers as well (binding a reference to virtual base is replaced by implicit conversion to a pointer to virtual base), with two additional rules:
</p>
<ol><li> <a href="static_cast.html" title="cpp/language/static cast"><code>static_cast</code></a> of a pointer to storage without an object is only allowed when casting to (possibly cv-qualified) <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">void</span><span class="sy2">*</span></span></span>.
</li><li> Pointers to storage without an object that were cast to possibly cv-qualified <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">void</span><span class="sy2">*</span></span></span> can only be <a href="static_cast.html" title="cpp/language/static cast"><code>static_cast</code></a> to pointers to possibly cv-qualified <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char</span></span></span>, or possibly cv-qualified <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span><span class="t-rev-inl t-since-cxx17"><span>, or possibly cv-qualified <a href="../types/byte.html" title="cpp/types/byte"><tt>std::byte</tt></a></span> <span><span class="t-mark-rev t-since-cxx17">(since C++17)</span></span></span>.
</li></ol>
<p>During construction and destruction it is generally allowed to call non-static member functions, access non-static data members, and use <a href="typeid.html" title="cpp/language/typeid"><code>typeid</code></a> and <a href="dynamic_cast.html" title="cpp/language/dynamic cast"><code>dynamic_cast</code></a>. However, because the lifetime either has not begun yet (during construction) or has already ended (during destruction), only specific operations are allowed. For one restriction, see <a href="virtual.html#During_construction_and_destruction" title="cpp/language/virtual">virtual function calls during construction and destruction</a>.
</p>
<h3><span class="mw-headline" id="Notes">Notes</span></h3>
<p>Until the resolution of <a rel="nofollow" class="external text" href="https://wg21.link/p1358r0#2256">core issue 2256</a>, the end of lifetime rules are different between non-class objects (end of storage duration) and class objects (reverse order of construction):
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> A
<span class="br0">{</span>
    <span class="kw4">int</span><span class="sy2">*</span> p<span class="sy4">;</span>
    ~A<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <a href="../io/cout.html"><span class="kw1762">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="sy2">*</span>p<span class="sy4">;</span> <span class="br0">}</span> <span class="co1">// undefined behavior since CWG2256: n does not outlive a</span>
                              <span class="co1">// well-defined until CWG2256: prints 123</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">void</span> f<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    A a<span class="sy4">;</span>
    <span class="kw4">int</span> n <span class="sy1">=</span> <span class="nu0">123</span><span class="sy4">;</span> <span class="co1">// if n did not outlive a, this could have been optimized out (dead store)</span>
    a.<span class="me1">p</span> <span class="sy1">=</span> <span class="sy3">&amp;</span>n<span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>Until the resolution of <a rel="nofollow" class="external text" href="https://wg21.link/p1971r0#RU007">RU007</a>, a non-static member of a const-qualified type or a reference type prevents its containing object from being transparently replaceable, which makes <span class="t-lc"><a href="../container/vector.html" title="cpp/container/vector">std::vector</a></span> and <span class="t-lc"><a href="../container/deque.html" title="cpp/container/deque">std::deque</a></span> hard to implement:
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw1">struct</span> X <span class="br0">{</span> <span class="kw4">const</span> <span class="kw4">int</span> n<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
<span class="kw1">union</span> U <span class="br0">{</span> X x<span class="sy4">;</span> <span class="kw4">float</span> f<span class="sy4">;</span> <span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">void</span> tong<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
    U u <span class="sy1">=</span> <span class="br0">{</span> <span class="br0">{</span> <span class="nu0">1</span> <span class="br0">}</span> <span class="br0">}</span><span class="sy4">;</span>
    u.<span class="me1">f</span> <span class="sy1">=</span> <span class="nu0">5</span>.<span class="me1">f</span><span class="sy4">;</span>                          <span class="co1">// OK: creates new subobject of 'u'</span>
    X <span class="sy2">*</span>p <span class="sy1">=</span> new <span class="br0">(</span><span class="sy3">&amp;</span>u.<span class="me1">x</span><span class="br0">)</span> X <span class="br0">{</span><span class="nu0">2</span><span class="br0">}</span><span class="sy4">;</span>            <span class="co1">// OK: creates new subobject of 'u'</span>
    <a href="../error/assert.html"><span class="kw775">assert</span></a><span class="br0">(</span>p<span class="sy2">-</span><span class="sy1">&gt;</span>n <span class="sy1">==</span> <span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span>                  <span class="co1">// OK</span>
    <a href="../error/assert.html"><span class="kw775">assert</span></a><span class="br0">(</span>u.<span class="me1">x</span>.<span class="me1">n</span> <span class="sy1">==</span> <span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span>                 <span class="co1">// undefined until RU007:</span>
                                        <span class="co1">// 'u.x' does not name the new subobject</span>
    <a href="../error/assert.html"><span class="kw775">assert</span></a><span class="br0">(</span><span class="sy2">*</span><a href="../utility/launder.html"><span class="kw1125">std::<span class="me2">launder</span></span></a><span class="br0">(</span><span class="sy3">&amp;</span>u.<span class="me1">x</span>.<span class="me1">n</span><span class="br0">)</span> <span class="sy1">==</span> <span class="nu0">2</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// OK even until RU007</span>
<span class="br0">}</span></pre></div></div>
<h3><span class="mw-headline" id="Defect_reports">Defect reports</span></h3>
<p>The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
</p>
<table class="dsctable" style="font-size:0.8em">
<tr>
<th> DR
</th>
<th> Applied to
</th>
<th> Behavior as published
</th>
<th> Correct behavior
</th></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/119.html">CWG 119</a>
</td>
<td> C++98
</td>
<td> an object of a class type with a non-trivial constructor can<br>only start its lifetime when theconstructor call has completed
</td>
<td> lifetime also started<br>for other initializations
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/201.html">CWG 201</a>
</td>
<td> C++98
</td>
<td> lifetime of a temporary object in a default argument<br>of a default constructor was required to end<br>when the initialization of the array completes
</td>
<td> lifetime ends before<br>initializing the next element<br>(also resolves <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/124.html">CWG  124</a>)
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/274.html">CWG 274</a>
</td>
<td> C++98
</td>
<td> an lvalue designating an out-of-lifetime object could be<br>used as the operand of static_cast only if the conversion<br>was ultimately to cv-unqualified <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char</span><span class="sy3">&amp;</span></span></span> or <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span><span class="sy3">&amp;</span></span></span>
</td>
<td> cv-qualified <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char</span><span class="sy3">&amp;</span></span></span><br>and <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span><span class="sy3">&amp;</span></span></span><br>also allowed
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/597.html">CWG 597</a>
</td>
<td> C++98
</td>
<td> the following behaviors were undefined:<br>1. a pointer to an out-of-lifetime object is implicitly<br>converted to a pointer to a non-virtual base class<br>2. an lvalue referring to an out-of-lifetime object<br>is bound to a reference to a non-virtual base class<br>3. an lvalue referring to an out-of-lifetime object is used<br>as the operand of a <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw1">static_cast</span></span></span> (with a few exceptions)
</td>
<td> made well-defined
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/2012.html">CWG 2012</a>
</td>
<td> C++98
</td>
<td> lifetime of references was specified to match storage duration,<br>requiring that extern references are alive before their initializers run
</td>
<td> lifetime begins<br>at initialization
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/2107.html">CWG 2107</a>
</td>
<td> C++98
</td>
<td> the resolution of <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/124.html">CWG  124</a> was not applied to copy constructors
</td>
<td> applied
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://wg21.link/P0137R1">P0137R1</a>
</td>
<td> C++98
</td>
<td> creating an object in an array of <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> reused its storage
</td>
<td> its storage is not reused
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/2256.html">CWG 2256</a>
</td>
<td> C++98
</td>
<td> lifetime of trivially destructible objects were inconsistent with other objects
</td>
<td> made consistent
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://wg21.link/P1971R0">P1971R0</a>
</td>
<td> C++98
</td>
<td> a non-static data member of a const-qualified type or a reference type<br>prevented its containing object from being transparently replaceable
</td>
<td> restriction removed
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://wg21.link/P2103R0">P2103R0</a>
</td>
<td> C++98
</td>
<td> transparently replaceability did not require keeping the original structure
</td>
<td> requires
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://wg21.link/P0593R6">P0593R6</a>
</td>
<td> C++98
</td>
<td> a pseudo-destructor call had no effects
</td>
<td> it destroys the object
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/CWG/issues/2470.html">CWG 2470</a>
</td>
<td> C++98
</td>
<td> more than one arrays may provide storage for the same object
</td>
<td> only one provides
</td></tr></table>
<h3><span class="mw-headline" id="References">References</span></h3>
<div class="t-ref-std-c++20">
<ul><li> C++20 standard (ISO/IEC 14882:2020): 
</li></ul>
<dl><dd><ul><li> 6.7.3 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 11.10.4 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<div class="t-ref-std-c++17">
<ul><li> C++17 standard (ISO/IEC 14882:2017): 
</li></ul>
<dl><dd><ul><li> 6.8 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 15.7 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<div class="t-ref-std-c++14">
<ul><li> C++14 standard (ISO/IEC 14882:2014): 
</li></ul>
<dl><dd><ul><li> 3 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 12.7 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<div class="t-ref-std-c++11">
<ul><li> C++11 standard (ISO/IEC 14882:2011): 
</li></ul>
<dl><dd><ul><li> 3.8 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 12.7 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<div class="t-ref-std-c++03">
<ul><li> C++03 standard (ISO/IEC 14882:2003): 
</li></ul>
<dl><dd><ul><li> 3.8 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 12.7 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<div class="t-ref-std-c++98">
<ul><li> C++98 standard (ISO/IEC 14882:1998): 
</li></ul>
<dl><dd><ul><li> 3.8 Object lifetime [basic.life] 
</li></ul>
</dd></dl>
<dl><dd><ul><li> 12.7 Construction and destruction [class.cdtor] 
</li></ul>
</dd></dl>
</div>
<h3><span class="mw-headline" id="See_also">See also</span></h3>
<table class="t-dsc-begin">

</table>

<!-- 
NewPP limit report
Preprocessor visited node count: 4711/1000000
Preprocessor generated node count: 13667/1000000
Post‐expand include size: 149244/2097152 bytes
Template argument size: 27696/2097152 bytes
Highest expansion depth: 20/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_en_:pcache:idhash:13096-0!*!0!!en!*!* and timestamp 20220726062320 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    Retrieved from "<a href="https://en.cppreference.com/mwiki/index.php?title=cpp/language/lifetime&amp;oldid=141373">https://en.cppreference.com/mwiki/index.php?title=cpp/language/lifetime&amp;oldid=141373</a>"                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>Navigation</h5>
            <ul><li><a href="https://en.cppreference.com/w/cpp/language/lifetime">Online version</a></li><li>Offline version retrieved 2022-07-30 14:05.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> This page was last modified on 25 July 2022, at 23:23.</li>
                                    <li id="footer-info-viewcount">This page has been accessed 214,463 times.</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.ColiruCompiler","ext.gadget.MathJax"], null, true);
}</script>
<script src="../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 0.038 secs. -->
	</body>
<!-- Cached 20220726063448 -->
</html>